package com.imesne.office.excel.read;

import com.imesne.office.excel.model.ExcelBook;
import com.imesne.office.excel.utils.ExcelKitUtils;

import java.io.File;

/**
 * Created by liyd on 17/6/30.
 */
public class ExcelReader {

    /**
     * 读取器配置
     */
    private ExcelReaderConfig excelReaderConfig;

    public ExcelReader(ExcelReaderConfig excelReaderConfig) {
        this.excelReaderConfig = excelReaderConfig;
    }


    /**
     * 读取excel文件
     *
     * @param excelFile the excel file
     * @return list
     */
    public ExcelBook read(File excelFile) {

        byte[] bytes = ExcelKitUtils.readFileToByte(excelFile);
        ExcelBookReader excelBookReader = excelReaderConfig.getExcelBookReader();
        ExcelBook excelBook = excelBookReader.readExcelBook(bytes);

        return excelBook;
    }


    /**
     * 读取excel文件
     *
     * @param bytes the bytes
     * @return list excel book
     */

    public ExcelBook read(byte[] bytes) {

        ExcelBookReader excelBookReader = excelReaderConfig.getExcelBookReader();
        ExcelBook excelBook = excelBookReader.readExcelBook(bytes);

        return excelBook;
    }


}
